package avatar

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/avatar"
	avatarReq "github.com/flipped-aurora/gin-vue-admin/server/model/avatar/request"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
	"github.com/flipped-aurora/gin-vue-admin/server/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type AvatarApi struct {
}

var avatarService = service.ServiceGroupApp.AvatarServiceGroup.AvatarService

// CreateAvatar 创建Avatar
// @Tags Avatar
// @Summary 创建Avatar
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body avatar.Avatar true "创建Avatar"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /avatar/createAvatar [post]
func (avatarApi *AvatarApi) CreateAvatar(c *gin.Context) {
	var avatar avatar.Avatar
	_ = c.ShouldBindJSON(&avatar)
	if err := avatarService.CreateAvatar(avatar); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteAvatar 删除Avatar
// @Tags Avatar
// @Summary 删除Avatar
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body avatar.Avatar true "删除Avatar"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /avatar/deleteAvatar [delete]
func (avatarApi *AvatarApi) DeleteAvatar(c *gin.Context) {
	var avatar avatar.Avatar
	_ = c.ShouldBindJSON(&avatar)
	if err := avatarService.DeleteAvatar(avatar); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteAvatarByIds 批量删除Avatar
// @Tags Avatar
// @Summary 批量删除Avatar
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除Avatar"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /avatar/deleteAvatarByIds [delete]
func (avatarApi *AvatarApi) DeleteAvatarByIds(c *gin.Context) {
	var IDS request.IdsReq
	_ = c.ShouldBindJSON(&IDS)
	if err := avatarService.DeleteAvatarByIds(IDS); err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateAvatar 更新Avatar
// @Tags Avatar
// @Summary 更新Avatar
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body avatar.Avatar true "更新Avatar"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /avatar/updateAvatar [put]
func (avatarApi *AvatarApi) UpdateAvatar(c *gin.Context) {
	var avatar avatar.Avatar
	_ = c.ShouldBindJSON(&avatar)
	if err := avatarService.UpdateAvatar(avatar); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindAvatar 用id查询Avatar
// @Tags Avatar
// @Summary 用id查询Avatar
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query avatar.Avatar true "用id查询Avatar"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /avatar/findAvatar [get]
func (avatarApi *AvatarApi) FindAvatar(c *gin.Context) {
	var avatar avatar.Avatar
	_ = c.ShouldBindQuery(&avatar)
	if reavatar, err := avatarService.GetAvatar(avatar.ID); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reavatar": reavatar}, c)
	}
}

// GetAvatarList 分页获取Avatar列表
// @Tags Avatar
// @Summary 分页获取Avatar列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query avatarReq.AvatarSearch true "分页获取Avatar列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /avatar/getAvatarList [get]
func (avatarApi *AvatarApi) GetAvatarList(c *gin.Context) {
	var pageInfo avatarReq.AvatarSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if list, total, err := avatarService.GetAvatarInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}

// Avatar 通过用户id获取头像的储存位置
// @Tags Avatar
// @Router /avatar/ [get]
func (avatarApi *AvatarApi) Avatar(c *gin.Context) {

}
